﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using efuture.http;
using efuture.xml;
using System.IO;

namespace Main
{
    public partial class frmLogin : DevExpress.XtraEditors.XtraForm
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            edtUserId.Text = "";

            HttpHelper.serverURL = edtServerURL.Text;
            String xmlData = XMLHelper.encode(pnlLoginInfo, "User");
            //MessageBox.Show(xmlData);

            xmlData = HttpHelper.DoPost("/sys/user/auth", xmlData, null);
            //MessageBox.Show(xmlData);

            if (XMLHelper.ShowException(xmlData, true)) {
                return;
            }

            XMLHelper.BindingData(pnlLoginSucc, new StringReader(xmlData), "/Root/*");

            if (String.IsNullOrEmpty(edtUserId.Text)) {
                return;
            }

            //MessageBox.Show(new XMLHelper().encode(panelControl1, "User"));

            HttpHelper.userId = edtUserId.Text;
            HttpHelper.userCode = edtUserCode.Text;

            this.DialogResult = DialogResult.OK;
        }

        private void labelControl2_Click(object sender, EventArgs e)
        {

        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2;
            this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}